home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / lib / tk / demos / mkForm.tcl < prev    next >
Encoding:
Text File  |  1995-07-21  |  1.5 KB  |  53 lines

  1. # mkForm w
  2. #
  3. # Create a top-level window that displays a bunch of entries with
  4. # tabs set up to move between them.
  5. #
  6. # Arguments:
  7. #    w -    Name to use for new top-level window.
  8.  
  9. proc mkForm {{w .form}} {
  10.     global tabList
  11.     catch {destroy $w}
  12.     toplevel $w
  13.     dpos $w
  14.     wm title $w "Form Demonstration"
  15.     wm iconname $w "Form"
  16.     message $w.msg -font -Adobe-times-medium-r-normal--*-180* -width 4i \
  17.         -text "This window contains a simple form where you can type in the various entries and use tabs to move circularly between the entries.  Click the \"OK\" button or type return when you're done."
  18.     foreach i {f1 f2 f3 f4 f5} {
  19.     frame $w.$i -bd 1m
  20.     entry $w.$i.entry -relief sunken -width 40
  21.     bind $w.$i.entry <Tab> "Tab \$tabList"
  22.     bind $w.$i.entry <Return> "destroy $w"
  23.     label $w.$i.label
  24.     pack $w.$i.entry -side right
  25.     pack $w.$i.label -side left
  26.     }
  27.     $w.f1.label config -text Name:
  28.     $w.f2.label config -text Address:
  29.     $w.f5.label config -text Phone:
  30.     button $w.ok -text OK -command "destroy $w"
  31.     pack $w.msg $w.f1 $w.f2 $w.f3 $w.f4 $w.f5 $w.ok -side top -fill x
  32.     set tabList "$w.f1.entry $w.f2.entry $w.f3.entry $w.f4.entry $w.f5.entry"
  33. }
  34.  
  35. # The procedure below is invoked in response to tabs in the entry
  36. # windows.  It moves the focus to the next window in the tab list.
  37. # Arguments:
  38. #
  39. # list -    Ordered list of windows to receive focus
  40.  
  41. proc Tab {list} {
  42.     set i [lsearch $list [focus]]
  43.     if {$i < 0} {
  44.     set i 0
  45.     } else {
  46.     incr i
  47.     if {$i >= [llength $list]} {
  48.         set i 0
  49.     }
  50.     }
  51.     focus [lindex $list $i]
  52. }
  53.